home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue66 / Clinic / ScopeTestMainForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-11-09  |  1.8 KB  |  79 lines

  1. unit ScopeTestMainForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TMainForm = class(TForm)
  11.     Button1: TButton;
  12.     Button2: TButton;
  13.     procedure Button1Click(Sender: TObject);
  14.     procedure Button2Click(Sender: TObject);
  15.   public
  16.     function Foo: Integer;
  17.     procedure ShowInt(I: Integer);
  18.   end;
  19.  
  20. var
  21.   MainForm: TMainForm;
  22.  
  23. implementation
  24.  
  25. uses
  26.   ScopeTestOtherForm;
  27.  
  28. {$R *.DFM}
  29.  
  30. var
  31.   Foo: Integer = 99;
  32.  
  33. function TMainForm.Foo: Integer;
  34. begin
  35.   Result := 1;
  36. end;
  37.  
  38. procedure TMainForm.ShowInt(I: Integer);
  39. begin
  40.   ShowMessageFmt('The value of this foo is: %d', [I])
  41. end;
  42.  
  43. procedure TMainForm.Button1Click(Sender: TObject);
  44. const
  45.   Foo: Integer = 57;
  46. begin
  47.   //Access local variable, parameter or nested routine
  48.   ShowInt(Foo);                    //57
  49.   //Access data field or method of this class
  50.   ShowInt(Self.Foo);               //1
  51.   //Access data field or method of other class
  52.   ShowInt(OtherForm.Foo);          //7
  53.   //Access variable or routine from this unit
  54.   ShowInt(ScopeTestMainForm.Foo);  //99
  55.   //Access variable or routine from other unit
  56.   ShowInt(ScopeTestOtherForm.Foo); //100
  57. end;
  58.  
  59. procedure TMainForm.Button2Click(Sender: TObject);
  60. const
  61.   Foo: Integer = 57;
  62. begin
  63.   with OtherForm do
  64.   begin
  65.     //Access local variable, parameter or nested routine
  66.     //Cannot be done from inside this with statement
  67.     //Access data field or method of this class
  68.     ShowInt(Self.Foo);               //1
  69.     //Access data field or method of other class
  70.     ShowInt(Foo);                    //7
  71.     //Access variable or routine from this unit
  72.     ShowInt(ScopeTestMainForm.Foo);  //99
  73.     //Access variable or routine from other unit
  74.     ShowInt(ScopeTestOtherForm.Foo); //100
  75.   end
  76. end;
  77.  
  78. end.
  79.